package me.zhengjie.modules.security.service;

import me.zhengjie.modules.security.service.dto.WebJwtUserDto;
import me.zhengjie.webuser.domain.WebUsers;
import me.zhengjie.webuser.service.WebUsersService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service("webUserDetailsService")
public class WebUserDetailsServiceImpl implements UserDetailsService {
    private final WebUsersService webUsersService;

    public WebUserDetailsServiceImpl(WebUsersService webUsersService) {
        this.webUsersService = webUsersService;
    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        WebUsers webUsers = webUsersService.findByEmailOrUsername(username);
        if (webUsers == null) {
            throw new UsernameNotFoundException("WebUser not found");
        }
        return new WebJwtUserDto(webUsers); // 根据实际情况转换
    }
}
